{layout name="layout1" /}
<style>
    .layui-table-cell {
        height:auto;
    }
    .goods-content>div:not(:last-of-type) {
        border-bottom:1px solid #DCDCDC;
    }
    .goods-data::after{
        display: block;
        content: '';
        clear: both;
    }
    .goods_name_hide{
        overflow:hidden;
        white-space:nowrap;
        text-overflow: ellipsis;
    }
    .operation-btn {
        margin: 5px;
    }
    .table-operate{
        text-align: left;
        font-size:14px;
        padding:0 5px;
        height:auto;
        overflow:visible;
        text-overflow:inherit;
        white-space:normal;
        word-break: break-all;
    }
</style>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
        <div class="layui-collapse like-layui-collapse" lay-accordion="" style="border:1px dashed #c4c4c4">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title like-layui-colla-title" style="background-color: #fff">操作提示</h2>
                <div class="layui-colla-content layui-show">
                    <p>*钢瓶操作记录，钢瓶轨迹查询</p>
                </div>
            </div>
        </div>
        </div>
        <div class="layui-tab layui-tab-card" lay-filter="tab-all">

<!--            <ul class="layui-tab-title">-->
<!--                <li data-type='' class="layui-this">全部</li>-->
<!--                <li data-type="1">实瓶</li>-->
<!--                <li data-type="2">空瓶</li>-->
<!--            </ul>-->

            <div class="layui-tab-item layui-show">
                <div class="layui-card">
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">钢瓶编码:</label>
                                <div class="layui-input-block">
                                    <input type="text" name="bottle_code" id="bottle_code" placeholder="请输钢瓶入编码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">操作类型:</label>
                                <div class="layui-input-block">
                                    <select name="type" id="type">
                                        <option value="">请选择操作类型</option>
                                        <option value="1">新瓶入库</option>
                                        <option value="2">充装</option>
                                        <option value="3">转运出</option>
                                        <option value="4">客户订单-送瓶</option>
                                        <option value="5">客户订单-取瓶</option>
                                        <option value="6">退瓶</option>
                                        <option value="7">转运回</option>
                                        <option value="8">检瓶</option>

                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">操作人ID:</label>
                                <div class="layui-input-block">
                                    <input type="text" name="admin_id" id="admin_id" placeholder="请输入操作人id" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">订单ID:</label>
                                <div class="layui-input-block">
                                    <input type="text" name="order_id" id="order_id" placeholder="请输入订单id" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">创建时间:</label>
                                <div class="layui-input-inline">
                                    <div class="layui-input-inline">
                                        <input type="text" name="start_time" class="layui-input" id="start_time"
                                               placeholder="" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-input-inline" style="margin-right: 5px;width: 20px;">
                                    <label class="layui-form-mid">至</label>
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="end_time" class="layui-input" id="end_time"
                                           placeholder="" autocomplete="off">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <button class="layui-btn layui-btn-sm layuiadmin-btn-ad {$view_theme_color}" lay-submit
                                        lay-filter="bottle-search">查询
                                </button>
                                <button class="layui-btn layui-btn-sm layuiadmin-btn-ad layui-btn-primary " lay-submit
                                        lay-filter="bottle-clear-search">清空查询
                                </button>
                            </div>
<!--                            <div class="layui-row">-->
<!--                                <div class="layui-inline">-->
<!--                                    <label class="layui-form-label">启用状态:</label>-->
<!--                                    <div class="layui-input-block">-->
<!--                                        <select name="use_status" id="use_status">-->
<!--                                            <option value="1">启用</option>-->
<!--                                            <option value="2">停用</option>-->
<!--                                        </select>-->
<!--                                    </div>-->
<!--                                </div>-->

<!--                            </div>-->

<!--                            </div>-->
                        </div>
                    </div>

                    <div class="layui-card-body">
<!--                        <div style="padding-bottom: 10px;">-->
<!--                            <button class="layui-btn layui-btn-sm layuiadmin-btn-bottle {$view_theme_color}" data-type="add">新增钢瓶</button>-->
<!--                        </div>-->
                        <table id="bottle-lists" lay-filter="bottle-lists"></table>
                        <script type="text/html" id="bottle-operation" >
                            <div class="table-operate">
                                <a class="layui-btn layui-btn-primary layui-btn-sm operation-btn" lay-event="detail">轨迹详情</a>
                                <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit">编辑</a>
<!--                                <a class="layui-btn layui-btn-danger layui-btn-sm operation-btn" lay-event="del">删除</a>-->
                            </div>
                        </script>
                        <script type="text/html" id="site_id">
                            <div class="layui-input-inline"  style="text-align: left;">
                                <p>站点:{{d.site_id??'--'}}</p>
                                <p>会员:{{d.user_id??'--'}}</p>
                            </div>
                        </script>
                        <script type="text/html" id="image">
                            <img src="{{d.image}}" style="height:80px;width: 80px" class="image-show">
                        </script>

                        <!--门店信息-->
                        <script type="text/html" id="shop">
                            <p>{{d.shop.name}}</p>
                        </script>

                        <!--订单信息-->
                        <script type="text/html" id="bottle">
                            <div style="text-align: left">
                                <p>订单编号:{{d.bottle_sn}}</p>
                                <p>订单类型:{{d.use_status_text}}</p>
                                <p>下单时间:{{d.create_time}}</p>
                                <p>支付时间:{{d.pay_time}}</p>
                                <p>订单来源:{{d.bottle_source_text}}</p>
                            </div>
                        </script>

                        <!--会员信息-->
                        <script type="text/html" id="user">
                            <img src="{{d.user.avatar}}" style="height:80px;width: 80px" class="image-show">
                            <div class="layui-input-inline"  style="text-align: left;">
                                <p>会员编号:{{d.user.sn}}</p>
                                <p style="width: 180px;text-overflow:ellipsis;overflow: hidden">会员昵称:{{d.user.nickname}}</p>
                                <p>会员等级:{{d.user_level}}</p>
                            </div>
                        </script>

                        <!--收货信息-->
                        <script type="text/html" id="delivery">
                            <div style="text-align: left">
                                <p>收货人:{{d.consignee}}</p>
                                <p>手机号码:{{d.mobile}}</p>
                                <p>收货地址:{{d.delivery_address}}</p>
                                <p>配送方式:{{d.delivery_type}}</p>
                            </div>
                        </script>

                        <!--金额信息-->
                        <script type="text/html" id="amount">
                            <div style="text-align: left">
                                <p>运费金额:{{d.shipping_price}}</p>
                                <p>商品金额:{{d.goods_price}}</p>
                                <p>优惠金额:{{d.discount_amount}}</p>
                                <p>应付金额:{{d.bottle_amount}}</p>
                                <p>支付方式:{{d.pay_way_text}}</p>
                            </div>
                        </script>

                        <!--商品信息-->
                        <script type="text/html" id="goods">
                            <div class="goods-content">
                                {{#  layui.each(d.bottle_goods, function(index, item){ }}
                                <div style="text-align: left;" class="goods-data">
                                    <img src="{{ item.image }}" style="height:80px;width: 80px" class="image-show layui-col-md4">
                                    <div class="layui-input-inline layui-col-md8">
                                        <span class="layui-col-md7 goods_name_hide">{{ item.goods_name }}</span>
                                        <span class="layui-col-md5">￥{{ item.goods_price }}</span>
                                        <br>
                                        <span class="layui-col-md7 goods_name_hide">{{ item.spec_value }}</span>
                                        <span class="layui-col-md5">{{ item.goods_num }}件</span>
                                    </div>
                                </div>
                                {{#  }); }}
                            </div>
                        </script>

                        <!--商品数量-->
                        <script type="text/html" id="goods_num">
                            {{ d.total_num }}件
                        </script>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.config({
        version:"{$front_version}",
        base: '/static/plug/layui-admin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'like', 'laydate'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , like = layui.like
            , element = layui.element
            , laydate = layui.laydate;
        var listType = '';
        $('.layui-btn.layuiadmin-btn-bottle').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //图片放大
        $(document).on('click', '.image-show', function () {
            var src = $(this).attr('src');
            like.showImg(src,600);
        });

        //监听搜索
        form.on('submit(bottle-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('bottle-lists', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });

        //事件
        var active = {
            add: function(){
                var index = layer.open({
                    type: 2
                    ,title: '新增钢瓶'
                    ,content: '{:url("bottle/add")}'
                    ,area: ['90%', '90%']
                    ,btn: ['保存', '取消']
                    ,maxmin: true
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'add-bottle-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID)
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field;
                            like.ajax({
                                url:'{:url("bottle/add")}',
                                data:field,
                                type:"post",
                                success:function(res)
                                {
                                    if(res.code == 1)
                                    {
                                        layui.layer.msg(res.msg, {
                                            offset: '15px'
                                            , icon: 1
                                            , time: 1000
                                        });
                                        layer.close(index); //关闭弹层
                                        table.reload('bottle-lists'); //数据刷新
                                    }
                                }
                            });
                        });

                        submit.trigger('click');
                    }
                });
            }
        }
        //清空查询
        form.on('submit(bottle-clear-search)', function () {
            $('#keyword').val('');
            $('#bottle_code').val('');
            $('#type').val('');
            $('#order_id').val('');
            $('#admin_id').val('');
            $('#start_time').val('');
            $('#end_time').val('');
            form.render('select');
            //刷新列表
            table.reload('bottle-lists', {
                where: [],
                page: {
                    curr: 1
                }
            });
        });

    
        //日期时间范围
        laydate.render({
            elem: '#start_time'
            ,type: 'datetime'
            ,trigger: 'click'
        });


        laydate.render({
            elem: '#end_time'
            ,type: 'datetime'
            ,trigger: 'click'
        });

        //获取列表
        getList(listType);
        //切换列表
        element.on('tab(tab-all)', function (data) {
            $('#keyword').val('');
            $('#bottle_status').val('');
            $('#goods_name').val('');
            $('#pay_way').val('');
            $('#use_status').val('');
            $('#start_time').val('');
            $('#end_time').val('');
            $('#delivery_type').val('');
            form.render('select');
            listType = $(this).attr('data-type');
            getList(listType);
            if (listType !== ''){
                $('.bottle_status').hide();
            }else {
                $('.bottle_status').show();
            }
        });

        function getList(type) {
            
             layui.define(['table', 'form'], function(exports){
                var $ = layui.$
                    ,table = layui.table
                    ,form = layui.form;
            var cols = [
                    {field:'id',title: 'id',width:60,align: 'center'}
                    , {field: 'bottle_code', title: '钢瓶编码', align: 'center',width:160}
                    , {field: 'type', title: '操作类型', align: 'center',width:160}
                    , {field: 'order_id', title: '订单ID', align: 'center',width:160}
                    , {field: 'admin_id', title: '操作人ID', align: 'center',width:160}
                    , {field: 'admin_id_name', title: '操作人姓名', align: 'center',width:160}
                    , {field: 'create_time', title: '创建时间', align: 'center',width:160}
                    , {field: 'info', title: '详细信息', align: 'center'}
                    // , {fixed: 'right', title: '操作', width: 260, align: 'center', toolbar: '#bottle-operation'}
                ];
            table.render({
                id:'bottle-lists'
                ,elem: '#bottle-lists'
                ,cols: [cols]
                , url: '{:url("bottleLog/lists")}?type=' + type
                ,cols: [cols]
                , page: true
                , text: {none: '暂无数据！'}
                , parseData: function (res) {
                    return {
                        "code": res.code,
                        "msg": res.msg,
                        "count": res.data.count,
                        "data": res.data.list,
                    };
                }
                ,done: function(res, curr, count){
                    // 解决操作栏因为内容过多换行问题
                    $(".layui-table-main tr").each(function (index, val) {
                        $($(".layui-table-fixed-l .layui-table-body tbody tr")[index]).height($(val).height());
                        $($(".layui-table-fixed-r .layui-table-body tbody tr")[index]).height($(val).height());
                    });
                }
            });
             });
        }

        //监听工具条
        table.on('tool(bottle-lists)', function (obj) {
            var id = obj.data.id;
            if(obj.event === 'detail'){
                layer.open({
                    type: 2
                    ,title: '订单详情'
                    ,content: '{:url("bottleLog/detail")}?id='+id
                    ,area: ['90%', '90%']
                    ,yes: function(index, layero){
                        table.reload('bottle-lists');
                    }
                })
            }

            //删除订单
            if(obj.event === 'del'){
                layer.confirm('删除后订单将消失，确认删除订单吗?', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    like.ajax({
                        url: '{:url("bottleLog/del")}'
                        , data: {'bottle_id': id}
                        , type: 'post'
                        , success: function (res) {
                            if (res.code == 1) {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                },function () {
                                    table.reload('bottle-lists');
                                });
                            }
                        },
                    });
                });
            }

            //取消订单
            if(obj.event === 'cancel'){
                layer.confirm('确认取消订单吗?', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    like.ajax({
                        url: '{:url("bottleLog/cancel")}'
                        , data: {'bottle_id': id}
                        , type: 'post'
                        , success: function (res) {
                            if (res.code == 1) {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                },function () {
                                    table.reload('bottle-lists');
                                });
                            }
                        },
                    });
                });
            }

            //发货
            if(obj.event === 'delivery'){
                layer.open({
                    type: 2
                    ,title: '订单发货'
                    ,content: '{:url("bottleLog/delivery")}?id='+id
                    ,area: ['90%', '90%']
                    ,yes: function(index, layero){

                    }
                })
            }

            //物流信息
            if(obj.event === 'express'){
                layer.open({
                    type: 2
                    ,title: '订单发货'
                    ,content: '{:url("bottleLog/express")}?id='+id
                    ,area: ['90%', '90%']
                    ,yes: function(index, layero){

                    }
                })
            }


            //确认收货
            if(obj.event === 'confirm'){
                layer.confirm('确认订单商品已收货吗?', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    like.ajax({
                        url: '{:url("bottleLog/confirm")}'
                        , data: {'bottle_id': id}
                        , type: 'post'
                        , success: function (res) {
                            if (res.code == 1) {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                },function () {
                                    table.reload('bottle-lists');
                                });
                            }
                        },
                    });
                });
            }

            //商家备注
            if(obj.event === 'remarks') {

                like.ajax({
                    url: '{:url("bottleLog/remarks")}'
                    , data: {'id': id}
                    , type: 'get'
                    , success: function (res) {
                        if (res.code === 1) {
                            layer.prompt({title: '备注信息', formType: 2, value: res.data.bottle_remarks}, function(value, index){
                                layer.close(index);
                                like.ajax({
                                    url: '{:url("bottleLog/remarks")}'
                                    , data: {'id': id, "bottle_remarks": value }
                                    , type: 'post'
                                    , success: function (res) {
                                        if (res.code === 1) {
                                            layui.layer.msg(res.msg, {
                                                offset: '15px'
                                                , icon: 1
                                                , time: 1000
                                            });
                                        }
                                    }
                                });

                            });
                        }
                    }
                });

            }


            if(obj.event ==='print'){
                layer.confirm('确定要打印订单吗？', function(index){
                    like.ajax({
                        url:'{:url("bottleLog/bottlePrint")}',
                        data:{id:id},
                        type:"post",
                        success:function(res)
                        {
                            if(res.code == 1)
                            {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                });
                                layer.close(index); //关闭弹层
                                table.reload('printer-lists'); //数据刷新
                            }
                        }
                    });
                    layer.close(index);


                })

            }
            if(obj.event === 'edit'){
                var id = obj.data.id;
                var index = layer.open({
                    type: 2
                    ,title: '编辑钢瓶'
                    ,content: '{:url("bottleLog/edit")}?id='+id
                    ,area: ['90%', '90%']
                    ,btn: ['保存', '取消']
                    ,maxmin: true
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'add-bottle-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field;
                            like.ajax({
                                url:'{:url("bottleLog/edit")}',
                                data:field,
                                type:"post",
                                success:function(res)
                                {
                                    if(res.code == 1)
                                    {
                                        layui.layer.msg(res.msg, {
                                            offset: '15px'
                                            , icon: 1
                                            , time: 1000
                                        },function () {
                                            layer.close(index); //关闭弹层
                                            table.reload('bottle-lists'); //数据刷新
                                        });

                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                    ,cancel: function(index, layero){
                        var window_index = index;
                        layer.confirm('数据未保存，确定关闭吗？', {
                            time: 0, //不自动关闭
                            btn: ['确定', '取消'],
                            yes: function(index){
                                layer.close(index);
                                layer.close(window_index);
                            }
                        });
                        return false;
                    }
                });
            }
        });
    });
</script>